<template>
  <div class="content">
    <!-- 宝贝收藏 -->
    <!-- <div class="contop">
      <input type="" placeholder="请输入要搜索的商品名称" /><button>
        宝贝搜索
      </button>
    </div> -->
    <!-- 内容List -->
    <div class="goodsList" v-if="goodsList.length > 0">
      <div
        v-for="item in goodsList"
        class="content container"
        :key="item.id"
        :class="item.goodStatus == 1 ? 'disabled_list' : ''"
      >
        <img
          :src="item.thumb"
          :style="{ cursor: item.goodStatus == 2 ? 'pointer' : '' }"
          height="180px"
          width="180px"
          @click="goDetail(item)"
        />
        <p>{{ item.name }}</p>
        <p>¥{{ item.priceCurrent / 100 }}/{{ item.unit }}</p>
        <img
          v-if="item.goodStatus == 1"
          src="/images/780.jpg"
          width="100px"
          height="100px"
          class="images"
        />
        <span @click="cancelCollection(item)">取消收藏</span>
      </div>
      <div
        v-for="(item, index) in 5 - (goodsList.length % 5)"
        style="width: 232px"
        :key="index"
      ></div>
    </div>
    <div class="paging" v-if="total > 0">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="10"
        layout="total, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <div class="wrap" v-else v-show="!loading">
      <div class="bomContent">
        <img
          alt=""
          height="330px"
          src="../../../../public/images/74.png"
          srcset=""
          width="330px"
        />
        <p>暂时没有您收藏的宝贝喲！</p>
      </div>
    </div>
  </div>
</template>

<script>
import { tMgdCollectPage } from "@/api/mallApi/congLinMall";
import { deleteCollect } from "@/api/mallApi/goods";
export default {
  name: "doteyCollect",
  data() {
    return {
      goodsList: [],
      currentPage: 1, //分页
      total: 0,
      loading: true,
    };
  },
  created() {
    this.getDoteyCollect();
  },
  methods: {
    goDetail(query) {
      console.log(query);
      if (query.goodStatus == 2) {
        this.$router.push({ path: "/mall/product?id=" + query.goodsId });
      }
    },
    cancelCollection(item) {
      console.log("宝贝", item);
      deleteCollect({ goodsIds: [item.goodsId] })
        .then((res) => {
          // 判断是否取消成功
          if (res.code === "00000") {
            this.$message.success("取消收藏成功");
            this.getDoteyCollect();
          }
        })
        .catch((err) => {});
    },
    getDoteyCollect() {
      let inpurValue = {
        pageSize: 10,
        pageNo: this.currentPage,
      };
      this.loading = true;
      tMgdCollectPage(inpurValue).then((res) => {
        console.log(res);
        this.goodsList = res.data.rows;
        this.total = res.data.totalRows;
        this.loading = false;
      });
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      console.log(this.currentPage);
      this.currentPage = val;
      this.getDoteyCollect();
    },
  },
};
</script>
<style lang="scss" scoped>
.disabled_list {
  cursor: no-drop;
  filter: grayscale(100%);
}
.container {
  position: relative; /* 设置容器为相对定位 */
  p:nth-child(4) {
    color: red;
    font-size: 15px;
    margin: 0;
    padding: 0;
    margin-left: 75px;
    font-weight: 700;
  }
  .images {
    position: absolute;
    top: 0;
    right: 0;
    border-radius: 50%;
    opacity: 0.8;
  }
}

.container span {
  display: none; /* 初始状态下不显示文本内容 */
  position: absolute; /* 将文本元素放在容器上面 */
  top: 48%;
  left: 11%; /* 水平居中 */
  padding: 8px; /* 添加一些间距 */
  background-color: #1289ff; /* 设置背景色 */
  color: white; /* 设置文字颜色 */
  border-radius: 4px; /* 添加边框圆角 */
  // display: block;
  width: 139px;
  height: 42px;
  text-align: center;
  opacity: 0.8;
  line-height: 1.5;
  font-size: 20px;
  cursor: pointer;
}

.container:hover span {
  display: block; /* 当鼠标悬浮在容器上时显示文本内容 */
}

.content {
  width: 1010px;
  height: 100%;
  background: #fff;
  margin: 20px 0 0 10px;
  .wrap {
    margin-left: 40%;
  }
}
.contop {
  margin-left: 10px;
  input {
    outline: none;
    width: 438px;
    height: 36px;
    border-radius: 4px;
    border: 2.5px solid #e5e5e5;
    background: #fff;
    font-family: "Source Han Sans CN";
    font-weight: 400;
    font-size: 14px;
    color: #a0a0a0;
    padding-left: 20px;
  }
  button {
    width: 111px;
    height: 36px;
    background: #f0f0f0;
    font-weight: 400;
    font-size: 16px;
    text-align: center;
    font-family: "Source Han Sans CN";
    font-weight: 500;
    font-size: 14px;
    text-align: center;
    color: #3c3c3c;
    border: #e5e5e5;
    cursor: pointer;
  }
}
.goodsList {
  // background-color: rgb(255, 254, 254);
  width: 100%;
  // height: 1100px;
  margin-bottom: 30px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  // overflow: hidden;
  .content {
    width: 180px;
    height: 290px;
    margin-top: 15px;
    //   border: 1px solid ;
    box-shadow: 1px 1px 1px 1px #fbfafa;
    //   background-color: #0479db;
    p:nth-child(2) {
      // font-family: "Source Han Sans CN Medium";
      font-weight: 700;
      font-size: 15px;
      color: #2b2b2b;
      overflow: hidden;
      /* 隐藏超出容器大小的部分 */
      white-space: nowrap;
      /* 不换行 */
      text-overflow: ellipsis;
      /* 显示省略号 */
      // background-color: aquamarine;
    }

    p:nth-child(3) {
      font-family: "Source Han Sans CN Bold";
      font-weight: 700;
      font-size: 18px;
      color: #ff6b00;
      padding: 0;
      margin: 0;
    }
  }
}
</style>
